import java.io.File;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DownTools {
    // 同步检验锁是怎么回事
	private static final ExecutorService sSERVICE = Executors
			.newSingleThreadExecutor();
	

	private void commit(DownLoadTask task) {
		if (task != null) {
			sSERVICE.execute(task);
		}
	}

	public void startDownLoad(String url, DownLoadListener listener) {
		if (TextUtils.isEmpty(url)) {
			return;
		}
		DownLoadTask task = new DownLoadUrl();
		task.onStart(url, listener);
		commit(task);
	}

	public static interface DownLoadTask extends Runnable {
		void onStart(String url, DownLoadListener listener);

		void onDownLoad();

	}

	public static interface DownLoadListener {

		void onSuccess();

		void onError();
	}

	public static interface DownLoadRequest {
		File getDownTarget(String fileName);

		URL getDownRequest(String url);
	}
}
